package com.ruoyi.web.controller.taskscore;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.YcTaskScore;
import com.ruoyi.service.IYcTaskScoreService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课题字典Controller
 *
 * @author ruoyi
 * @date 2020-09-08
 */
@Controller
@RequestMapping("/ruoyi/score")
public class YcTaskScoreController extends BaseController {
    private String prefix = "ruoyi/score";

    @Autowired
    private IYcTaskScoreService ycTaskScoreService;

    @RequiresPermissions("ruoyi:score:view")
    @GetMapping()
    public String score() {
        return prefix + "/score";
    }

    /**
     * 查询课题字典列表
     */
    @RequiresPermissions("ruoyi:score:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YcTaskScore ycTaskScore) {
        startPage();
        List<YcTaskScore> list = ycTaskScoreService.selectYcTaskScoreList(ycTaskScore);
        return getDataTable(list);
    }

    /**
     * 导出课题字典列表
     */
    @RequiresPermissions("ruoyi:score:export")
    @Log(title = "课题字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YcTaskScore ycTaskScore) {
        List<YcTaskScore> list = ycTaskScoreService.selectYcTaskScoreList(ycTaskScore);
        ExcelUtil<YcTaskScore> util = new ExcelUtil<YcTaskScore>(YcTaskScore.class);
        return util.exportExcel(list, "score");
    }

    /**
     * 新增课题字典
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存课题字典
     */
    @RequiresPermissions("ruoyi:score:add")
    @Log(title = "课题字典", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YcTaskScore ycTaskScore) {
        return toAjax(ycTaskScoreService.insertYcTaskScore(ycTaskScore));
    }

    /**
     * 修改课题字典
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        YcTaskScore ycTaskScore = ycTaskScoreService.selectYcTaskScoreById(id);
        mmap.put("ycTaskScore", ycTaskScore);
        return prefix + "/edit";
    }

    /**
     * 修改保存课题字典
     */
    @RequiresPermissions("ruoyi:score:edit")
    @Log(title = "课题字典", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YcTaskScore ycTaskScore) {
        return toAjax(ycTaskScoreService.updateYcTaskScore(ycTaskScore));
    }

    /**
     * 删除课题字典
     */
    @RequiresPermissions("ruoyi:score:remove")
    @Log(title = "课题字典", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ycTaskScoreService.deleteYcTaskScoreByIds(ids));
    }
}
